import numpy as np
import cv2
import time

#函数：建立视频捕获对象
#参数：0-本地摄像头，1 2 3...-外接摄像头，'视频路径/名称.格式'
cap = cv2.VideoCapture(0)


fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('/home/cty/python/output.avi',fourcc,20.0,(640,480))

#函数：检测摄像头设备是否初始化成功
#返回参数：True False
while (cap.isOpened()):
        #函数：读取一帧数据
        #返回参数：是否读取成功，读取的一帧数据
	ret,frame = cap.read()

	#gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
	
	now_time_stamp = time.time()
	now_time_stamp_array = time.localtime(now_time_stamp)
	now_time_style = time.strftime('%Y-%m-%d %H:%M:%S',now_time_stamp_array)
	print('date:',now_time_style)
	print('width:',cap.get(3))
	print('height:',cap.get(4))
	#print('frames number:',cap.get(7))



	out.write(frame)

	cv2.imshow('frame',frame)

	if cv2.waitKey(1) & 0xFF == ord('q'):
		break

cap.release()
out.release()
cv2.destroyAllWindows()

